﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Pheonix.CodeLibrary.Web;
using Pheonix.Fashionzoomer.DAL;
using Pheonix.Fashionzoomer.Entity.SqlServer2000;

public partial class private_favorites : PrivateBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Title = SiteName + " - Favorites";
    }

    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        LoadData();
    }

    public string MaleOrFemale(object maleFemale)
    {
        if ((bool)maleFemale == true)
            return "Mens";
        else
            return "Womens";
    }

    private void LoadData()
    {
        int CurrentPage = dataPager.CurrentPage;

        DataTable favoriteItems = CustomCommand.GetFavoriteProducts(SessionManager.LoggedUser.Id);
 
        PagedDataSource pagedDataSource = new PagedDataSource();
        pagedDataSource.AllowPaging = true;
        pagedDataSource.DataSource = favoriteItems.DefaultView;
        pagedDataSource.PageSize = 10;
        pagedDataSource.CurrentPageIndex = CurrentPage - 1;

        dataPager.PrevPageEnabled = !pagedDataSource.IsFirstPage;
        dataPager.NextPageEnabled = !pagedDataSource.IsLastPage;

        dataPager.LastPage = pagedDataSource.PageCount;
        //if (!IsPostBack)
        //{         
        dataPager.SetPageLinks();
        //}

        productList.DataSource = pagedDataSource;
        productList.DataBind();

        if (favoriteItems.Rows.Count > 0)
        {
            pnlEmptyMessage.Visible = false;
            pnlDataPager.Visible = true;
        }
        else
        {
            pnlEmptyMessage.Visible = true;
            pnlDataPager.Visible = false;
        }

    }

    protected void productList_Command(object sender, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            Favorites.DeleteFavorites(Convert.ToInt32(e.CommandArgument));
            LoadData();
        }
    }
}
